{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a636f6f3-00d7-4248-8c36-3da51190e882",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-0.04053403 -0.05560051 -0.04385472 ...  0.09371872  0.02846981\n",
      " -0.00576814]\n"
     ]
    }
   ],
   "source": [
    "from langchain_community.embeddings import AscendEmbeddings\n",
    "\n",
    "model = AscendEmbeddings(\n",
    "    model_path=\"/root/.cache/modelscope/hub/yangjhchs/acge_text_embedding\",\n",
    "    device_id=0,\n",
    "    query_instruction=\"Represend this sentence for searching relevant passages: \",\n",
    ")\n",
    "emb = model.embed_query(\"hellow\")\n",
    "print(emb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8d29ddaa-eef3-4a4e-93d8-0f1c13525fb4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "We strongly recommend passing in an `attention_mask` since your input_ids may be padded. See https://huggingface.co/docs/transformers/troubleshooting#incorrect-output-when-padding-tokens-arent-masked.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.00348254  0.03098977 -0.00203087 ...  0.08492374  0.03970494\n",
      "  -0.03372753]\n",
      " [-0.02198593 -0.01601127  0.00215684 ...  0.06065163  0.00126425\n",
      "  -0.03634358]]\n"
     ]
    }
   ],
   "source": [
    "doc_embs = model.embed_documents(\n",
    "    [\"This is a content of the document\", \"This is another document\"]\n",
    ")\n",
    "print(doc_embs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "797a720d-c478-4254-be2c-975bc4529f57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<coroutine object Embeddings.aembed_query at 0x7f9fac699cb0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.aembed_query(\"hellow\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "57e62e53-4d2c-4532-9b77-a46bc3da1130",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.04053403, -0.05560051, -0.04385472, ...,  0.09371872,\n",
       "        0.02846981, -0.00576814], dtype=float32)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await model.aembed_query(\"hellow\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7e260457-8b50-4ca3-8f76-8a76d8bba8c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<coroutine object Embeddings.aembed_documents at 0x7fa093ff1a80>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.aembed_documents(\n",
    "    [\"This is a content of the document\", \"This is another document\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ce954b94-aaac-4d2c-80be-b2988c16af6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.00348254,  0.03098977, -0.00203087, ...,  0.08492374,\n",
       "         0.03970494, -0.03372753],\n",
       "       [-0.02198593, -0.01601127,  0.00215684, ...,  0.06065163,\n",
       "         0.00126425, -0.03634358]], dtype=float32)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "await model.aembed_documents(\n",
    "    [\"This is a content of the document\", \"This is another document\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7823d69d-de79-4f95-90dd-38f4bdeb9bcc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
